import sys

def prn(x):
	print x,

def sol1(matrix, n):
	for i in range(n):
		for j in range(n):
			if i < n/2:
				if i == 0:
					matrix[i][j] = j+1
				if (i == 1) and (j > i - 1) and (j < n - i):
					matrix[i][j] = j + (n - 1)*4
				if (i == 2) and (j > i - 1) and (j < n - i):
					matrix[i][j] = 21 + (j - 3) + (n - 3)*4

def sol2(matrix, n):
	incs = { 'u': (-1, 0, 'r'), 'd': (1, 0, 'l'), 'l': (0, -1, 'u'), 'r': (0, 1, 'd') }
	direction = 'r'
	location = (0, 0)
	def out(loc, n):
		return loc[0] < 0 or loc[1] < 0 or loc[0] >= n or loc[1] >= n
	
	for counter in range(1, n*n+1):
		# set the value
		matrix[location[0]][location[1]] = counter
		#counter += 1

		# find the new good location
		for i in range(3): # limit attempts number to 4
			# get the increment from the direction
			increment = (incs[direction][0], incs[direction][1])

			# calculate the new location
			new_location = (location[0] + increment[0], location[1] + increment[1])

			# check if the new location isn't out or already occupied
			if out(new_location, n) or matrix[new_location[0]][new_location[1]] != 0:
				direction = incs[direction][2]
			else:
				location = new_location
				break


while True:
	n = int(raw_input("\nEnter matrix size> "))

	if n < 1 or n > 19:
		print "wrong value"
		sys.exit(1)

	matrix = []
	for i in range(n):
		line = []
		for j in range(n):
			line.append(0)
		matrix.append(line)


	sol2(matrix, n)

	for i in range(n):
		for j in range(n):
			prn("%3d"%matrix[i][j])
		prn('\n')
		